package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelComment;
import cn.wolfcode.trip.base.mapper.TravelCommentMapper;
import cn.wolfcode.trip.base.query.CommentQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommentService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TravelCommentServiceImpl implements ITravelCommentService {
    @Autowired
    private TravelCommentMapper travelCommentMapper;

    @Override
    public PageInfo query(CommentQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<TravelComment> list = travelCommentMapper.queryForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(TravelComment travelComment) {
        if (travelComment.getId() != null) {
            travelCommentMapper.updateByPrimaryKey(travelComment);
        } else {
            //设置当前用户
            travelComment.setUser(UserContext.getCurrentUser());
            travelCommentMapper.insert(travelComment);
        }

    }

    @Override
    public List<TravelComment> listAll() {
        return null;
    }

    @Override
    public TravelComment get(Long id) {
        return null;
    }

    @Override
    public void saveOrUpdate(TravelComment travelComment, String[] tags) {

    }

    @Override
    public Integer queryCountByTravelId(Long TravelId) {
        return travelCommentMapper.queryCountByTravelId(TravelId);
    }
}
